package com.cheyunkeji.er.view.auction;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cheyun.netsalev3.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/** Created by Michael on 2017/8/25 9:24. */
public class SimpleItemTextView extends RelativeLayout {

  @BindView(R.id.tv_tittle)
  TextView tvTittle;

  @BindView(R.id.tv_content)
  TextView tvContent;

  @BindView(R.id.content_view)
  RelativeLayout contentView;

  private String txtContent;
  private String txtTitle;
  private View rootView;

  public SimpleItemTextView(Context context) {
    super(context);
    initView(context);
  }

  public SimpleItemTextView(Context context, AttributeSet attrs) {
    super(context, attrs);
    initView(context);

    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.SimpleItemTextView);

    for (int i = 0; i < typedArray.getIndexCount(); i++) {

      switch (typedArray.getIndex(i)) {
        case R.styleable.SimpleItemTextView_sitv_title:
          txtTitle = typedArray.getString(typedArray.getIndex(i));
          tvTittle.setText(txtTitle);
          break;
        case R.styleable.SimpleItemTextView_sitv_content:
          txtContent = typedArray.getString(typedArray.getIndex(i));
          tvContent.setText(txtContent);
          break;
        case R.styleable.SimpleItemTextView_sitv_bkg:
          contentView.setBackgroundColor(
              typedArray.getColor(typedArray.getIndex(i), Color.parseColor("#00000000")));
        default:
          break;
      }
    }
    typedArray.recycle();
  }

  public SimpleItemTextView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
  }

  private void initView(Context context) {

    rootView = LayoutInflater.from(context).inflate(R.layout.er_sitv_layout, this, true);
    ButterKnife.bind(this, rootView);
  }

  public void setTitle(String title) {
    tvTittle.setText(title);
  }

  public void setContent(String content) {
    tvContent.setText(content);
  }
}
